package com.yanqu.road.server.timer;

import com.yanqu.road.server.CrossBaseServer;
import com.yanqu.road.server.TempMgr;
import com.yanqu.road.server.manager.rank.IRankDataMgr;
import com.yanqu.road.utils.executor.GeneralTask;

import java.util.Calendar;

public class MgrDataSaveTask extends GeneralTask {

    @Override
    public void doRun() {
        for (TempMgr baseMgr : CrossBaseServer.getInstance().getMgrList()) {
            if(baseMgr instanceof IRankDataMgr){
                continue;
            }
            try {
                if("CrossFiveHeroMgr".equals(baseMgr.getClass().getSimpleName())){
                    Calendar calNow = Calendar.getInstance();
                    int minute = calNow.get(Calendar.MINUTE);
                    if(minute % 15 == 0){
                        long stratTime = System.currentTimeMillis();
                        baseMgr.save();
                        long cost = System.currentTimeMillis() - stratTime;
                        getLOGGER().info("{} save cost {} mills.", baseMgr.getClass().getSimpleName(),cost);
                    }else {
                        getLOGGER().info("{} not in save time", baseMgr.getClass().getSimpleName());
                    }
                }else {
                    long stratTime = System.currentTimeMillis();
                    baseMgr.save();
                    long cost = System.currentTimeMillis() - stratTime;
                    getLOGGER().info("{} save cost {} mills.", baseMgr.getClass().getSimpleName(),cost);
                }

            } catch (Exception e) {
                getLOGGER().error("{} save error.", baseMgr.getClass().getSimpleName(), e);
            }
        }
    }

}
